<!--
 * @Descripttion: 订单基本信息
 * @version: 
 * @Author: mmzhang
 * @Date: 2021-07-20 14:48:37
 * @LastEditTime: 2022-11-01 14:06:30
-->
<template>
  <div class="order-msg flex">
    <i class="iconfont order-img icon-icon_list1">&#xe61f;</i>
    <div class="order-content flex flex-horizontal-between">
      <ul class="flex flex-wrap flex-horizontal-between">
        <li
          v-for="(item, index) in msgList"
          :key="index"
          :class="['flex', 'flex-vertical-center', { 'width-100': item.key == 'contractCode' }]">
          <p>
            <span v-show="item.key != 'counselorName'">{{ orderStatusName }}</span>{{ item.name }}:
          </p>
          <p>
            {{ baseMsg[item.key] }}
            <span v-show="item.key == 'counselorName'">({{ baseMsg['workNo'] }})</span>
          </p>
        </li>
      </ul>
      <div class="order-status">
        <div class="flex flex-vertical-center">
          <p>{{ baseMsg.showStatusName }}</p>
          <Button
            type="primary"
            style="margin-left: 20px"
            v-show="showExamineFun()"
            @click="examineFun"
            :disabled="isShowTips == 3">
            审核
          </Button>
        </div>
        <div class="tips" v-if="isShowTips == 1">！该认购单价格已低于底价</div>
        <div class="tips" v-if="isShowTips == 2">！该签约单价格低于认购单且低于底价</div>
        <div class="tips" v-if="isShowTips == 3">
          ！包销项目请先完成底价上传，
          <span @click="linkRoomFun">立即前往</span>
        </div>
      </div>
    </div>
    <!--审核-->
    <dt-modal-edit ref="examineEdit" title="请进行审核" @ok="submitExamine" :label-width="200">
      <p slot="bottom" v-if="otherTips != ''">{{ otherTips }}</p>
    </dt-modal-edit>
  </div>
</template>
<script>
  import comMgr from '@/biz/sales/salesCommon'
  import ParamsExamine from './examine.js'
  export default {
    props: ['detailMsg', 'orderStatusName', 'examineBtn', 'businessId'],
    data() {
      return {
        otherTips: '',
        loading: false,
        showChannel: false, // 是否展示渠道费用
        examineForm: {
          approveResult: '', //审核结果
          isBackTimely: '', // 及时
          rejectReason: '', // 原因
          channelCostValue: '', // 渠道费用
          breakLowPriceReason: '', // 破底价说明
          breakAnnex: [] // 破底价附件
        },
        msgList: [
          {
            name: '单编号',
            key: 'contractCode'
          },
          {
            name: '客户',
            key: 'customerName'
          },
          {
            name: '房源',
            key: 'roomName'
          },
          {
            name: '所属顾问',
            key: 'counselorName'
          },
          {
            name: '日期',
            key: 'contractDate'
          }
        ],
        baseMsg: {},
        isShowTips: 0 // 1展示认购 2展示签约  3没底价
      }
    },
    created() {
      this.baseMsg = {
        ...this.detailMsg.orContractBaseInfoVO
      }
      let nameTxt =
        this.detailMsg.orContractWebInfoVO.channelName.split('-').length > 1
          ? this.detailMsg.orContractWebInfoVO.channelName.split('-')[1]
          : ''

      if (this.detailMsg.orContractWebInfoVO.cooperationType == 6) {
        this.showChannel = false
        // 提示信息
        this.otherTips = `该订单为${nameTxt}渠道订单，渠道合作类型及费用将在订单审核通过后由${nameTxt}运营人员填写!`
      } else {
        this.showChannel =
          this.detailMsg.orContractWebInfoVO.cooperationType == 1 &&
          (this.orderStatusName == '认购' || this.orderStatusName == '签约')
        this.otherTips = ''
      }

      if (typeof this.detailMsg.orContractWebInfoVO.channelCost !== 'number') {
        this.examineForm.channelCostValue = '0'
      } else {
        this.examineForm.channelCostValue = this.detailMsg.orContractWebInfoVO.channelCost.toString()
      }

      // 破底价
      // 大小包销
      if (
        this.detailMsg.orContractBaseInfoVO.coopMode == 4 ||
        this.detailMsg.orContractBaseInfoVO.coopMode == 5
      ) {
        if (
          (this.baseMsg.statusName.indexOf('认购待审核') > -1 ||
            this.baseMsg.statusName.indexOf('签约待审核') > -1) &&
          this.detailMsg.orContractBaseInfoVO.isBreakLowPrice != 1
        ) {
          if (
            this.detailMsg.orRoomDetailsVO.basicTotalPrice == '-' ||
            this.detailMsg.orRoomDetailsVO.basicPrice == '-'
          ) {
            this.isShowTips = 3
          } else {
            if (this.orderStatusName == '签约') {
              // 签约单价低于认购单价且低于底单价或签约总价低于认购总价且低于底总价
              if (
                (Number(this.detailMsg.orContractWebInfoVO.unitPrice) <
                  Number(this.detailMsg.orContractWebInfoVO.price) &&
                  Number(this.detailMsg.orContractWebInfoVO.unitPrice) <
                    Number(this.detailMsg.orRoomDetailsVO.basicPrice)) ||
                (Number(this.detailMsg.orContractWebInfoVO.totalPrice) <
                  Number(this.detailMsg.orContractWebInfoVO.sumPrice) &&
                  Number(this.detailMsg.orContractWebInfoVO.totalPrice) <
                    Number(this.detailMsg.orRoomDetailsVO.basicTotalPrice))
              ) {
                this.isShowTips = 2
              }
            } else {
              // 认购单价或认购总价低于底单价或底总价
              if (
                Number(this.detailMsg.orContractWebInfoVO.price) <
                  Number(this.detailMsg.orRoomDetailsVO.basicPrice) ||
                Number(this.detailMsg.orContractWebInfoVO.sumPrice) <
                  Number(this.detailMsg.orRoomDetailsVO.basicTotalPrice)
              ) {
                this.isShowTips = 1
              }
            }
          }
        } else {
          this.isShowTips = 0
        }
      } else {
        this.isShowTips = 0
      }
    },
    mounted() {},
    methods: {
      showExamineFun() {
        let type = this.baseMsg.contractCode.slice(0, 2)
        switch (type) {
          case 'RG':
            return (
              this.baseMsg.statusName.indexOf('待审核') > -1 &&
              this.unlocking('0104010101') &&
              this.detailMsg.orContractBaseInfoVO.isBreakLowPrice != 1
            )
          case 'UR':
            return (
              this.baseMsg.statusName.indexOf('待审核') > -1 &&
              this.detailMsg.orContractBaseInfoVO.isBreakLowPrice != 1 &&
              (this.$route.query.returnPurchase ? this.unlocking('0206100101') : this.unlocking('0104020101'))
            )
          case 'QY':
            return (
              this.baseMsg.statusName.indexOf('待审核') > -1 &&
              this.unlocking('0104030101') &&
              this.detailMsg.orContractBaseInfoVO.isBreakLowPrice != 1
            )
          case 'UQ':
            return (
              this.baseMsg.statusName.indexOf('待审核') > -1 &&
              this.detailMsg.orContractBaseInfoVO.isBreakLowPrice != 1 &&
              (this.$route.query.returnNote ? this.unlocking('0206100201') : this.unlocking('0104040101'))
            )
          default:
            break
        }
      },
      // 跳转 房源管理
      linkRoomFun() {
        this.$router.push({
          name: 'buildingResources'
        })
      },
      examineFun() {
        this.$refs.examineEdit.show(new ParamsExamine(this).options(), this.examineForm)
      },
      // 提交审核
      submitExamine() {
        let _this = this
        let breakObj = {
          breakLowPriceAnnex: this.examineForm.breakAnnex
            .map((item) => {
              return item.url
            })
            .join(',')
        }

        let formVal = this.$tool.deepClone(this.examineForm)
        formVal.isBackTimely = formVal.isBackTimely == '1' ? true : false
        formVal.channelCostValue = formVal.channelCostValue == '-' ? '' : formVal.channelCostValue
        let params = Object.assign(
          {
            businessId: this.businessId,
            type: this.$dt
              .dictInfo()
              .orderType.filter(
                (item) => _this.baseMsg.statusName.indexOf(item.dictLabelCn.slice(0, 2)) > -1
              )[0].dictValue
          },
          formVal,
          breakObj
        )
        this.loading = true
        comMgr
          .submitExamine(params)
          .then((res) => {
            this.$Message.success(!res ? '审核成功' : res)
            this.$emit('onGetOrderDetail')
            this.$emit('auditSuccess')
            this.loading = false
          })
          .catch((res) => {
            this.loading = false
          })
      }
    }
  }
</script>
<style lang="scss" scoped>
  .order-msg {
    padding: 10px 30px;
    width: 100%;
    background-color: #f2f2f2;

    .order-content {
      height: 120px;
      width: 100%;
      background-color: #f2f2f2;
      font-size: 18px;
    }

    .order-img {
      margin: 15px 0;
      width: 30px;
      height: 30px;
      color: #0f42a7;
      font-size: 24px;
    }

    .back-img {
      margin: auto 0;
      width: 80px;
      height: 64px;
    }

    .order-status {
      display: flex;
      position: relative;
      padding-left: 3%;
      width: 30%;
      border-left: 1px solid #d7d7d7;
      font-size: 24px;
    }

    .tips {
      position: absolute;
      bottom: 5px;
      background-color: rgba(254, 252, 236, 1);
      font-size: 14px;
      padding: 0 5px;
      height: 32px;
      line-height: 32px;
      text-align: center;

      span {
        color: #2d8cf0;
        border-bottom: 1px solid #2d8cf0;
        cursor: pointer;
      }
    }
  }
</style>
